package com.kcnet.qk.activity;

import android.content.Intent;
import android.provider.Settings;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;

import com.kcnet.qk.Common.FuncItemFactory;
import com.kcnet.qk.R;
import com.kcnet.qk.adapter.FuncAdapter;
import com.kcnet.qk.constant.Const;
import com.kcnet.qk.controller.hdyh.HdyhAoduReplyCTR;
import com.kcnet.qk.controller.hdyh.HdyhFriendSendMsgCTR;
import com.kcnet.qk.util.AppUtil;
import com.kcnet.qk.util.PreferenceHelper;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/4/27.
 */

public class HdyhActivity extends BaseActivity {
    private final static int MINI_VERSION_CODE = 16;
    private final static String SNACKBAR_TXT = "当前您使用的系统版本过低，请更新高版本系统再使用";

    @BindView(R.id.ll)
    FrameLayout mLlRootView;

    @BindView(R.id.bannerContainer)
    FrameLayout mFlBannerContainer;

    @BindView(R.id.ryv)
    RecyclerView mRecyclerView;

    private boolean mIsFirstJump = false;
    private FuncAdapter mAdapter;

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new FuncAdapter(this, FuncItemFactory.getInstance().createmHDYHFuncItems());
        mRecyclerView.setAdapter(mAdapter);
        //AppUtil.jumpToWx(this);
    }

    @Override
    protected void initData() {
        // only for build version larger equal than api 18

    }

    @Override
    protected void setListener() {
        mAdapter.setOnItemClickListener(new FuncAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                String funcName = FuncItemFactory.getInstance().createmHDYHFuncItems().get(position).funcName;
                switch (funcName) {
                    case FuncItemFactory.HDYH_HYLT:
                        ArrayList<String> list = new ArrayList<String>();
                        list.add("asdadadasdasd");
                        list.add("dgsdfgsdf");
                        list.add("vvvvvvvvvvv");
                        list.add("xxxxxxxxxxxx");
                        list.add("4234");
                        list.add("bbfddf");
                        list.add("67867867868");

                        HdyhFriendSendMsgCTR.getInstance().setParms(5,2,5,list);
                        startAddPeople(Const.WX_HDYH_HYLT);
                        break;
                    case FuncItemFactory.HDYH_ZDHF:
                        List<String> klist = new ArrayList<String>();
                        List<String> clist = new ArrayList<String>();
                        klist.add("asdasd");
                        clist.add("aaaaaasd");
                        HdyhAoduReplyCTR.getInstance().setParms(0,klist,clist);
                        //HdFriendTimeLineZans.getInstance().setParms(3,2,5,3);
                        startAddPeople(Const.WX_HDYH_ZDHF);
                        break;
                    //case FuncItemFactory.HDYH_TGHYQQ:

                     //   startAddPeople(Const.KEY_HDYH_yh);
                      //  break;
                }
            }
        });
    }


    private void startAddPeople(final int addType) {
        PreferenceHelper.putBoolean(Const.PREF_KEY_STOP_AUTO_FLAG, true);
        prepareAddPeople(addType);
    }

    private void prepareAddPeople(int addType) {

        PreferenceHelper.putInt(Const.PREF_KEY_ADD_PEOPLE_TYPE, addType);
        EventBus.getDefault().post(new Boolean(true));
        EventBus.getDefault().post(new Integer(addType));
        if (!AppUtil.checkPermission(this)) {
            jumpSetting();
            mIsFirstJump = true;
        } else {

            AppUtil.jumpToWX(this);
        }
    }



    private void jumpSetting() {
        // jump to setting permission
        Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
        startActivity(intent);
    }

}
